home *** CD-ROM | disk | FTP | other *** search
/ MACD 5 / MACD 5.bin / workbench / libs / unixlib.lha / unix / src / devices.c < prev    next >
C/C++ Source or Header  |  1995-09-05  |  753b  |  34 lines

  1. #include "amiga.h"
  2. #include "devices.h"
  3.  
  4. struct IORequest *_device_open(char *name, ULONG unit, ULONG flags,
  5.                    APTR data, ULONG data_len, int req_size)
  6. {
  7.     struct MsgPort *port;
  8.     struct IORequest *ioreq;
  9.  
  10.     if ((port = CreateMsgPort()) && (ioreq = CreateIORequest(port, req_size))) {
  11.     if (data) {
  12.         struct IOStdReq *io2 = (struct IOStdReq *) ioreq;
  13.         io2->io_Data = data;
  14.         io2->io_Length = data_len;
  15.     }
  16.     if (OpenDevice(name, unit, ioreq, flags) == 0)
  17.         return ioreq;
  18.     }
  19.     if (ioreq)
  20.     DeleteIORequest(ioreq);
  21.     if (port)
  22.     DeletePort(port);
  23.     return 0;
  24. }
  25.  
  26. void _device_close(struct IORequest *ioreq)
  27. {
  28.     if (ioreq) {
  29.     CloseDevice(ioreq);
  30.     DeletePort(ioreq->io_Message.mn_ReplyPort);
  31.     DeleteIORequest(ioreq);
  32.     }
  33. }
  34.